<?php 
namespace app\Admin\controller;
use think\Controller;
use app\admin\model\Users;
use app\admin\model\User_rank;
use app\admin\model\Feedback;
use app\admin\model\Payment;
use app\admin\model\User_account;
use app\admin\model\Member_grade;
class Member extends Base
{
	
	public function member_list(){
		$memberlist=new Users();
		$memberlist=$memberlist->paginate(1);
		$page = $memberlist->render();
		$this->assign('page', $page);
		$this->assign("memberlist",$memberlist);
		return $this->fetch();
	}

	public function member_list_edit(){
		$memberlist=new Users();
		$data["user_name"]=input("post.user_name");
		$data["email"]=input("post.email");
		$data["password"]=input("post.password");
		$data["qq"]=input("post.qq");
		$data["mobile_phone"]=input("post.mobile_phone");
		$user_id=input("post.user_id");
		$res=$memberlist->upd1($data,$user_id);
		if ($res) {
			$this->redirect("http://shop.net/index.php/admin/Member/member_list.html");	
		}
	}

	public function member_add(){
		$model=new Users();
		$data=input("post.");
		$res=$model->add($data);
		if ($res) {
			$this->success('添加会员成功~~~', 'member/member_list');
		}
		return $this->fetch();
	}
	
	public function apply(){
		return $this->fetch();
	}

	public function add_apply(){
		$model=new Payment();
		$apply=$model->select();
		$this->assign("apply",$apply);
		return $this->fetch();
	}

	public function add_apply_do(){
		$model=new User_account();
		$data=input("post.");
		$res=$model->add($data);
		if ($res) {
			$this->success('添加充值和申请成功~~~', 'member/member_list');
		}
	}

	public function member_leav_message(){
		$member_leav_message=new Feedback();
		$member_leav_message=$member_leav_message->paginate(1);
		$page = $member_leav_message->render();
		$this->assign('page', $page);
		$this->assign("member_leav_message",$member_leav_message);
		return $this->fetch();
	}

	public function member_leav_json(){
		$model=new Feedback();
		$msg_id=$_POST["msg_id"];
		$msg_status=$_POST["msg_status"];
		if ($msg_status==1) {
			$res=$model->upd($msg_id);
		}else{
			$res=$model->upd1($msg_id);
		}
		if ($res) {
			$arr["status"]=1;
			$arr["data"]="";
			$arr["msg"]="更新成功";
		}else{
			$arr["status"]=0;
			$arr["data"]="";
			$arr["msg"]="更新失败";
		}
		echo json_encode($arr);
	}

	public function member_grade(){
		$member_grade=new User_rank();
		$member_grade=$member_grade->paginate(1);
		$page = $member_grade->render();
		$this->assign('page', $page);
		$this->assign("member_grade",$member_grade);
		return $this->fetch();
	}

	public function add_grade(){
		return $this->fetch();
	}

	public function feedback(){
		$feedback=new feedback();
		$grade=$feedback->select();
		$this->assign("feedback",$feedback);
		return $this->fetch();
	}

	public function member_add_data(){
		$data=input("post.");
		$model=new Users();
		$res=$model->add($data);
		if ($res) {
			$this->success('新增会员成功~~~', 'member/member_list');
		}
	}

	public function add_rank()
	{
		$data=input("post.");
		$model=new User_rank();
		$rs=$model->add_data($data);
		if($rs){
			$this->success('新增会员等级成功~~~', 'member/member_grade');
		}
	}

	public function fund_management(){
		return $this->fetch();
	}

	public function money_detail(){
		return $this->fetch();
	}

	public function adjust_member(){
		return $this->fetch();
	}

	public function del_member(){
		$model=new Users();
		$user_id=$_GET["user_id"];
		$res=$model->del($user_id);
		if ($res) {
			$this->success('您已删除。。','member/member_list');
		}
	}

	public function member_edit(){
		$model=new Users();
		$user_id=$_GET["user_id"];
		$data=$model->find($user_id);
		$this->assign("data",$data);
		return $this->fetch();
	}

	public function edit_qq(){
		$model=new Users();
		$user_id=$_POST["user_id"];
		$qq=$_POST["qq"];
		$res=$model->upd($qq,$user_id);
		echo json_encode($qq);
	}

	public function select_xq()
	{
		$model=new Feedback();
		$msg_id=$_GET["msg_id"];
		$msg=$model->fetch($msg_id);
		$this->assign("msg",$msg);
		return $this->fetch();
	}

	public function select_xq_edit()
	{
		$model=new Feedback();
		$msg_id=$_POST["msg_id"];
		$order_id=$_POST["order_id"];
		if ($order_id==0) {
			$model->upd3($msg_id);
		}
	}

	public function select_xq_del(){
		$model=new Feedback();
		$msg_id=$_GET["msg_id"];
		$msg=$model->del($msg_id);
		if ($msg) {
			$this->redirect("http://shop.net/index.php/admin/Member/member_leav_message.html");
		}
	}

	public function member_reply()
	{
		$model=new Feedback();
		$msg_content=$_POST["msg_content"];
		$data=[
			"msg_content"=>$msg_content,
		];
		$model->save($data);
		
	}
	public function upd_display()
	{
		$model=new Feedback();
		$msg_id=$_POST["msg_id"];
		$msg_status=$_POST["msg_status"];
		if ($msg_status==1) {
			$r=$model->upd($msg_id);
			$arr=[
				"status"=>1,
				"data"=>$r,
			];
		}else{
			$r=$model->upd1($msg_id);
			$arr=[
				"status"=>2,
				"data"=>$r,
			];
		}
		echo json_encode($arr);
	}

	public function collect_goods_area(){
		return $this->fetch();
	}

	public function select_order(){
		return $this->fetch();
	}

	public function user_recharge(){
		return $this->fetch();
	}

}


